<?php

namespace app\modules\setting\configs\seller;

use app\common\enum\ConfigEnum;
use app\common\enum\EtcOfficeProductSelected_SendStatusEnum;
use app\common\enum\FormEnum;
use sookie\excel\SaveExcel;
use yii\db\ActiveRecord;
use sookie\react\handlers\UrlHandler;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use app\modules\setting\models\seller\EtcOfficeProductSelected;
use sookie\bootstraps\handlers\AuthChecker;

/**
* Class TestConfig
* @package sookie\react\configs
* app\modules\setting\configs\seller\SelectedConfig 模型的配置类
*/
class SelectedConfig{

    /**
    * @return array
    * 获取搜索表单配置
    */
    public static function getSearchConfig(){
    return [
            [
                "component" => "FormInput",
                "field" => "code",
                "label" => "选品ID",
                "placeholder" => "选品ID",
                "allowClear" => true,
            ],

    ];
    }

    /**
    * @return array
    * 获取表格的操作
    */
    public static function getTableActions(){
        return  [
        ];
    }

    /**
    * @return array
    * 获取表格行的操作
    * [] 表示要id, ["*"] 表示要一行记录,参数名record, ["id"] 指定需要的参数 ， selected_ids 表示需要所有选择的id
    * configParamsField 规定请求的时候带上数据行中的那些参数，只需要字段名
    */
    public static function getTableRowAction(){
        return [
            [
                "actionType" => "MODAL",
                "config" => [
                    "footer" => true,
                    "title" => "发货信息",
                    "alert" => [
                        "description" => "填写以下表单修改数据模型"
                    ]
                ],
                "configUri" => UrlHandler::toAction("seller/selected","update"),
                "auth" => AuthChecker::doPermissionCheck("seller/selected","update"),
                "configParamsField" => ["id"],
                "label" => "发货",
                ConfigEnum::CALLBACK => function($item,$config){
                    $send_status = ArrayHelper::getValue($item,'send_status');
                    if($send_status == EtcOfficeProductSelected_SendStatusEnum::NO){
                        $label = $config['label'];
                    }else{
                        $label = EtcOfficeProductSelected_SendStatusEnum::getMsg($send_status);
                    }
                    return [
                        'label' => $config['label'],
                        'new_label' => $label,
                        'show' => true,
                    ];
                }
            ],
        ];
    }

    /**
    * @return array
    * 获取表格配置
    */
    public static function getTableConfig(){
        return [
            "rowKey" => "id",
            "columns" => [
                [
                    "title" => "选品ID",
                    "dataIndex" => "code",
                    "sorter" => true,
                    "key" => "code",
                    "format" => "text",
                ],
//                [
//                    "title" => "机构",
//                    "dataIndex" => "user_id",
//                    "sorter" => true,
//                    "key" => "user_id",
//                    "format" => "text",
//                ],
//                [
//                    "title" => "商家",
//                    "dataIndex" => "seller_id",
//                    "sorter" => true,
//                    "key" => "seller_id",
//                    "format" => "text",
//                ],
                [
                    "title" => "产品",
                    "dataIndex" => "product_id",
                    "sorter" => true,
                    "key" => "product_id",
                    "format" => "raw",
                ],
//                [
//                    "title" => "是否选中",
//                    "dataIndex" => "is_select",
//                    "sorter" => true,
//                    "key" => "is_select",
//                    "format" => "text",
//                ],
                [
                    "title" => "发货状态",
                    "dataIndex" => "send_status",
                    "sorter" => true,
                    "key" => "send_status",
                    "format" => "text",
                ],
                [
                    "title" => "申请时间",
                    "dataIndex" => "apply_time",
                    "sorter" => true,
                    "key" => "apply_time",
                    "format" => "text",
                ],

                [
                    "title" => "发货时间",
                    "dataIndex" => "send_time",
                    "sorter" => true,
                    "key" => "send_time",
                    "format" => "text",
                ],
                [
                    "title" => "发样数量",
                    "dataIndex" => "send_sample_num",
                    "sorter" => true,
                    "key" => "send_sample_num",
                    "format" => "text",
                ],
                [
                    "title" => "发货地址",
                    "dataIndex" => "send_sample_address_id",
                    "sorter" => true,
                    "key" => "send_sample_address_id",
                    "format" => "text",
                ],
                [
                    "title" => "发货单号",
                    "dataIndex" => "send_code",
                    "sorter" => true,
                    "key" => "send_code",
                    "format" => "text",
                ],
                [
                    "title" => "拍摄状态",
                    "dataIndex" => "video_status",
                    "sorter" => true,
                    "key" => "video_status",
                    "format" => "text",
                ],
            ],
            "actions" => self::getTableRowAction()
        ];
    }

    /**
    * 首页配置
    */
    public static function configIndex(){
        return [
            //搜索表单配置
            "searchConfig" => self::getSearchConfig(),
            // 操作配置 configParams 规定请求的时候带上那些参数
            "actionDivConfig" => self::getTableActions(),
            //表格配置
            "tableConfig" => self::getTableConfig(),
        ];
    }




    /**
    * @param ActiveRecord $model
    * @return array
    * 修改-表单配置
    */
    public static function configUpdate(ActiveRecord $model){
        return [
            "type" => "FORM",
            "formSubmitUri" => UrlHandler::toAction("seller/selected","update",["id" => $model->id]),
            "config" => [
                [
                    "component" => FormEnum::FormText,
                    "disabled" => true,
                    "field" => "user_id",
                    "label" => "机构",
                    "placeholder" => "机构",
                    "allowClear" => true,
                    "initialValue" => $model->user_id . "",
                    "rules" => [
                    ],
                ],
                [
                    "component" => FormEnum::FormText,
                    "disabled" => true,
                    "field" => "product_id",
                    "label" => "产品",
                    "placeholder" => "产品",
                    "allowClear" => true,
                    "initialValue" => $model->product_id . "",
                    "rules" => [
                    ],
                ],
                [
                    "component" => FormEnum::FormText,
                    "disabled" => true,
                    "field" => "send_sample_num",
                    "label" => "发样数量",
                    "placeholder" => "发样数量",
                    "allowClear" => true,
                    "initialValue" => $model->send_sample_num . "",
                    "rules" => [
                    ],
                ],
                [
                    "component" => FormEnum::FormText,
                    "disabled" => true,
                    "field" => "send_sample_address_id",
                    "label" => "发货地址",
                    "placeholder" => "发货地址",
                    "allowClear" => true,
                    "initialValue" => $model->send_sample_address_id . "",
                    "rules" => [
                    ],
                ],
                [
                    "component" => FormEnum::FormMulInput,
                    "field" => "send_code",
                    "label" => "发货单号",
                    "placeholder" => "发货单号",
                    "allowClear" => true,
                    "initialValue" => $model->send_code,
                    "rules" => [
                        [
                            'required' => true
                        ]
                    ],
                ],
            ],
        ];
    }


}

